package framework.util.queryFilter.vo;

import java.util.List;

/**
 * @author 吴宇亮 on 2019/2/23 0023 14:12
 */
public class Update<BoType> extends AbstactSql {

    private String tableName;
    private BoType bo;

    //用于mapper文件拼接sql
    private List<_Field> fieldList;

    @Override
    public void generatorSql(Class clazz) throws NoSuchFieldException {
        //生成要udpate的sql, 要这种格式：url='123', name='123'
        StringBuilder sb = new StringBuilder(fieldList.size() * 30);
        for(int i = 0, j = fieldList.size(); i < j; i++){
            _Field field = fieldList.get(i);
            if(i != j - 1)
                sb.append(field.get_fieldName() + " = #{bo."+field.getFieldName()+",jdbcType="+field.getFieldType()+"}, ");
            else
                sb.append(field.get_fieldName() + " = #{bo."+field.getFieldName()+",jdbcType="+field.getFieldType()+"} ");
        }
        this.generatorSql = sb.toString();
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public BoType getBo() {
        return bo;
    }

    public void setBo(BoType bo) {
        this.bo = bo;
    }

    public List<_Field> getFieldList() {
        return fieldList;
    }

    public void setFieldList(List<_Field> fieldList) {
        this.fieldList = fieldList;
    }
}
